package ferp.android.views.table.element.misere;

import android.content.Context;
import android.graphics.Rect;
import android.view.View;
import ferp.android.GUI;
import ferp.android.views.table.TableView;
import ferp.android.views.table.element.Element;
import ferp.core.card.Card;
import ferp.core.game.Settings;

/**
 * User: olegs
 * Date: 07/01/2015 17:24
 */
public class MisereDesk extends Element<MisereDeskView>
{
  public MisereDesk(Context context, TableView parent) {super(context, parent);}

  public void layout(Rect misere, Rect bid0, Rect trick, Rect turn0, Rect hand2, Rect trickCounter0, boolean landscape, int padding, int declarer)
  {
    view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    int l = 0, w = view.getMeasuredWidth(), h = view.getMeasuredHeight();

    switch (declarer)
    {
      case 1:
        l = landscape ? GUI.center(w, padding, bid0.left) : GUI.center(w, padding, trick.left);
        break;

      case 2:
        l = landscape ? GUI.center(w, turn0.right, hand2.right) : GUI.center(w, trick.right, hand2.right);
        break;
    }

    int t = landscape ? trickCounter0.bottom - h : trick.top + (trick.height() - h) / 2;

    misere.set(l, t, l + w, t + h);

    layout(misere);
  }

  public void show(Rect misere, Rect bid0, Rect trick, Rect turn0, Rect hand2, Rect trickCounter0, boolean landscape, int padding, int declarer)
  {
    layout(misere, bid0, trick, turn0, hand2, trickCounter0, landscape, padding, declarer);
    show(true);
  }

  // delegation
  public void reset() {view.reset();}
  public void set(int hash, Settings.RankOrder order) {view.set(hash, order);}
  public void switchOrder(Settings.RankOrder order) {view.switchOrder(order);}
  public void mark(Card c) {view.mark(c);}

  @Override
  protected final MisereDeskView create(Context context, TableView parent) {return new MisereDeskView(context);}
}
